//
//  WSTableViewCell.m
//  DigitalGeek
//
//  Created by lienbao on 19/08/2014.
//  Copyright (c) 2014 com.lienbao.digitalgeek. All rights reserved.
//

#import "TableViewCell.h"
#import "ZuLinPrefixHeader.pch"
@interface TableViewCell ()
{
    UIView *_imageShowView;
}
@property (nonatomic, strong) UIView *topLine;
@property (nonatomic, strong) UIView *bottomLine;

@end

@implementation TableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  if(self){
        self.backgroundColor = [UIColor whiteColor];
        _topLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 0.5)];
        _topLine.backgroundColor = [UIColor grayColor];
        _topLine.alpha = 0.5;
        _bottomLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 0.5)];
        _bottomLine.backgroundColor = [UIColor grayColor];
        _bottomLine.alpha = 0.5;
         }
    return self;
}

- (void)awakeFromNib
{
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)imgClickToBig:(UIImage *)img {
  UIWindow *window=[UIApplication sharedApplication].keyWindow;
  _imageShowView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
  _imageShowView.backgroundColor=[UIColor colorWithWhite:0.1 alpha:0.7];
  [window addSubview:_imageShowView];
  
  UIImageView *imageView = [[UIImageView alloc]initWithFrame:_imageShowView.frame];
  imageView.image = img;
  imageView.tag = 1;
  imageView.contentMode = UIViewContentModeScaleAspectFit;
  [_imageShowView addSubview:imageView];
  
  UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hideImage:)];
  [_imageShowView addGestureRecognizer: tap];
}

//隐藏图片
-(void)hideImage:(UITapGestureRecognizer*)tap{
  [_imageShowView removeFromSuperview];
  
}



- (void)addTopLine
{
    [self addTopLineyOffset:0.5];
}

- (void)addTopLineyOffset:(CGFloat)y
{
    [self addTopLine:y xOffset:0];
}

- (void)addTopLinexOffset:(CGFloat)x
{
    [self addTopLine:0.5 xOffset:x];
}

- (void)addTopLine:(CGFloat)y xOffset:(CGFloat )x
{
    _topLine.frame = CGRectMake(x, y, ScreenWidth, 0.5);
    if (![_topLine superview]) {
        [self.contentView addSubview:_topLine];
    }
}


- (void)removeTopLine
{
    [_topLine removeFromSuperview];
}

- (void)addBottomLine
{
    [self addBottomLineyOffset:[[self class] cellHeight] - 0.5];
}

- (void)addBottomLineyOffset:(CGFloat)y
{
    [self addBottomLine:y xOffset:0];
}

- (void)addBottomLinexOffset:(CGFloat)x
{
    [self addBottomLine:[[self class] cellHeight] - 0.5 xOffset:x];
}

- (void)addBottomLine:(CGFloat)y xOffset:(CGFloat )x
{
    _bottomLine.frame = CGRectMake(x, y, ScreenWidth, 0.5);
    if (![_bottomLine superview]) {
        [self.contentView addSubview:_bottomLine];
    }
}

- (void)addBottomLine:(CGFloat )x width:(CGFloat )width
{
    _bottomLine.frame = CGRectMake(x, [[self class] cellHeight] - 0.5, width, 0.5);
    if (![_bottomLine superview]){
        [self.contentView addSubview:_bottomLine];
    }
}

- (void)removeBottomLine
{
    [_bottomLine removeFromSuperview];
}

- (void)tableViewCellWithData:(id)data forIndexPath:(NSIndexPath *)indexPath
{
    
}

+ (CGFloat)cellHeight
{
    return 30;
}

+ (CGFloat)accordHeight:(id)data forIndexPath:(NSIndexPath *)indexPath
{
    return [self cellHeight];
}

- (CGSize)sizeWithString:(NSString *)string font:(UIFont *)font
{
    CGRect rect = [string boundingRectWithSize:CGSizeMake(0, 800)//限制最大的宽度和高度
                                       options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesFontLeading  |NSStringDrawingUsesLineFragmentOrigin//采用换行模式
                                    attributes:@{NSFontAttributeName: font}//传人的字体字典
                                       context:nil];
    return rect.size;
}

- (CGSize)sizeWithStringAndWidth:(CGFloat)width string:(NSString *)string font:(UIFont *)font
{
    CGRect rect;
    if ([string isEqual:[NSNull null]] ) {
       return rect.size;
    } else {
        CGRect rect = [string boundingRectWithSize:CGSizeMake(width, 800)//限制最大的宽度和高度
                                           options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesFontLeading  |NSStringDrawingUsesLineFragmentOrigin//采用换行模式
                                        attributes:@{NSFontAttributeName: font}//传人的字体字典
                                           context:nil];
        return rect.size;
    }
}

- (CGSize)sizeWithStringAndHeight:(CGFloat)height string:(NSString *)string font:(UIFont *)font
{
    CGRect rect = [string boundingRectWithSize:CGSizeMake(0, height)//限制最大的宽度和高度
                                       options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesFontLeading  |NSStringDrawingUsesLineFragmentOrigin//采用换行模式
                                    attributes:@{NSFontAttributeName: font}//传人的字体字典
                                       context:nil];
    return rect.size;
}

-(BOOL)isEmptyString:(NSString *)string11
{
    if (string11 == NULL || string11 == nil || [[string11 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length]== 0) {
        return NO;
    } else {
        return YES;
    }
}

+(NSString *)reuseIdentifier{
    return @"";
}
@end
